// StudentInitializationBeforeUse.aj
//
// Informatics 102 Spring 2012
// Code Example
//
// This aspect applies the code necessary to require that certain methods
// will fail when called on a Student object that has not yet been
// initialized.  Note that it is a lot like the previous version of this
// aspect.  The primary changes are in the pointcuts that identify methods
// that are initializers and that require initialization; where we previously
// listed methods explicitly, we're now using annotations to match them
// automatically.


public aspect StudentInitializationBeforeUse
{
	private boolean Student.isInitialized = false;
	
	
	pointcut initializationOfStudent(Student s):
		execution(@Initializer * Student.*(..)) && this(s);
	
	
	void around(Student s):
		initializationOfPerson(s)
	{
		proceed(s);
		s.isInitialized = true;
	}
	
	
	pointcut methodsThatRequireInitialization(Student s):
		execution(@RequiresInitialization * Student.*(..)) && this(s);
	
	
	before(Student s):
		methodsThatRequireInitialization(s)
	{
		if (!s.isInitialized)
		{
			throw new UninitializedException();
		}
	}
}
